import jdk.swing.interop.SwingInterOpUtils;

public class Test {
    // 递归求斐波那契数列的第 N 项
    public static int fib (int n ){
        if (n==1 || n==2){
            return 1;
        }
      int temp= fib(n-1)+fib(n-2);
        return temp;
    }
    public static void main(String[] args) {
        System.out.println(fib(4));
    }
    //写一个递归方法，输入一个非负整数，返回组成它的数字之和
    public static int sumN(int n ){
        if (n <= 9){
            return n;
        }
        int temp=( n % 10 )+sumN( n / 10);
        return temp;
    }
    public static void main5(String[] args) {

        System.out.println(sumN(1234));

    }
    //按顺序打印一个数字的每一位(例如 1234 打印出 1 2 3 4)（递归）
    public static void printNum (int n){
        if (n<=9){
            System.out.println(n);;

        }else{
            System.out.println(n % 10);
            printNum(n/10);
        }

    }
    public static void main4(String[] args) {
        printNum(1234);
    }
    //递归求 1 + 2 + 3 + ... + 10
    public static int sumNUM (int m ){
        if(m==1){
            return 1;
        }
        int temp = m+sumNUM(m-1);
        return temp;
    }
    public static void main3(String[] args) {
        sumNUM(10);
        System.out.println(sumNUM(10));
    }
    //n!
    public static int print (int n ){
        if (n==1){
            return 1;
        }
        int temp=n*print(n-1);
        return temp;
    }
    public static void main2(String[] args) {
        int a=print(3);
        System.out.println( a);
    }

    //汉诺塔
    public static int countNUM =0;
    public static void hanio (int n,char pos1,char pos2,char pos3){

        if (n==1){
            move(pos1,pos3);
            return;
        }
        hanio(n-1,pos1,pos3,pos2);
        move(pos1,pos3);
        hanio(n-1,pos2,pos1,pos3);
    }
    public static void move (char posStr,char posDes){
        countNUM++;
        System.out.println(posStr+"-->"+posDes+" ");
    }
    public static void main1(String[] args) {
        hanio(3,'A','B','C');
        System.out.println(countNUM);
    }
}

